package org.swift.mashup.engine.model;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import org.swift.mashup.engine.concurrency.agenda.ActionTemplate;

public abstract class BaseActionTemplate implements ActionTemplate {
	
	protected From from;
	protected Activity activity;
	
	private Map<String, With> withs = new HashMap<String, With>();
	private Map<String, Constant> constants = new HashMap<String, Constant>();
	private Set<When> whens = new HashSet<When>();
	private String name;
	private boolean publish;
	private String encoding;
	private String mashupName;
	
	//for testing
	public BaseActionTemplate() {}
	
	public BaseActionTemplate(String name, From from, Activity activity,
			Map<String, With> withs, Collection<When> whens, Map<String, Constant> constants, String encoding) {
		this(name,from,activity,withs, whens,constants,encoding,false);
	}
	
	public BaseActionTemplate(String name, From from, Activity activity,
			Map<String, With> withs, Collection<When> whens,
			Map<String, Constant> constants, String encoding, boolean publish) {
		this.name = name;
		this.from = from;
		this.activity = activity;
		this.withs.putAll(withs);
		this.constants.putAll(constants);
		this.whens.addAll(whens);
		this.setPublish(publish);
		this.encoding = encoding;
	}

	public String getName() {
		return name;
	}

	public void addWith(String name, With with) {
		this.withs.put(name, with);
	}

	public void addWhen(When condition) {
		this.whens.add(condition);
	}

	public Map<String, With> getWiths() {
		return Collections.unmodifiableMap(withs);
	}
	
	public Map<String, Constant> getConstants() {
		return Collections.unmodifiableMap(constants);
	}

	public Set<When> getWhens() {
		return Collections.unmodifiableSet(whens);
	}
	
	public From getFrom() {
		return from;
	}

	public boolean isPublish() {
		return publish;
	}

	public void setPublish(boolean publish) {
		this.publish = publish;
	}
	
	public String getEncoding() {
		return encoding;
	}
	
	public void setEncoding(String encoding) {
		this.encoding = encoding;
	}
	
	public String getMashupName() {
		return mashupName;
	}
	
	public void setMashupName(String mashupName) {
		this.mashupName = mashupName;
	}
}
